package com.peng.community.config;

import com.peng.community.controller.interceptor.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMVCConfig implements WebMvcConfigurer {

    @Autowired
    AlphaInterceptor alphaInterceptor;

    @Autowired
    LoginInterceptor loginInterceptor;

    @Autowired
    LoginRequireInterceptor loginRequireInterceptor;

    @Autowired
    MessageInterceptor messageInterceptor;


    @Autowired
    DataInterceptor dataInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(alphaInterceptor). //默认情况下拦截所有路径
            excludePathPatterns("/**/*.css", "/**/*.jpg", "/**/*.png", "/**/*.jpeg", "/**/*.js")
                .addPathPatterns("/register", "/login");//指定拦截的请求

        registry.addInterceptor(loginInterceptor). //拦截所有路径
                excludePathPatterns("/**/*.css", "/**/*.jpg", "/**/*.png", "/**/*.jpeg", "/**/*.js");

        registry.addInterceptor(loginRequireInterceptor). //拦截所有路径
                excludePathPatterns("/**/*.css", "/**/*.jpg", "/**/*.png", "/**/*.jpeg", "/**/*.js");

        registry.addInterceptor(messageInterceptor).
                excludePathPatterns("/**/*.css", "/**/*.jpg", "/**/*.png", "/**/*.jpeg", "/**/*.js");

        registry.addInterceptor(dataInterceptor).
                excludePathPatterns("/**/*.css", "/**/*.jpg", "/**/*.png", "/**/*.jpeg", "/**/*.js");

    }
}
